import { defineStore } from 'pinia'
import type { LoginUserVO } from '@/model/LoginModel'
import { ref, reactive, computed } from 'vue'
export const useUserInfoStore = defineStore('userInfo', () => {
  //用户信息对象
  const userInfo = reactive<LoginUserVO>({
    id: '',
    username: '',
    realName: '',
    phoneNumber: '',
    mail: '',
  })
  /**
   * 修改用户信息
   */
  function setUserInfo(user: LoginUserVO) {
    Object.assign(userInfo, user)
  }
  /**
   * 获取用户对象
   */
  const getUserInfo = computed(() => userInfo)
  //token
  const token = ref<string>('')
  /**
   * 修改token
   */
  function setToken(newToken: string) {
    token.value = newToken
  }
  /**
   * 获取token
   */
  const getToken = computed(() => token.value)
  return {
    setToken,
    setUserInfo,
    getToken,
    getUserInfo,
  }
})
